import type { BlogParams } from '@/models/blog'
import request from './request'

//获取用户信息
export function getPersonalBlogInfo(id?: number) {
  return request({
    method: 'get',
    url: 'blog/getPersonalBlogInfo',
    params: {
      userId: id
    }
  })
}
//获取用户的博客
export function getPersonalBlog(id?: number) {
  return request({
    method: 'get',
    url: 'blog/getPersonalBlog',
    params: {
      userId: id
    }
  })
}
//获取博客详情
export function getBlog(id: number) {
  return request({
    method: 'get',
    url: 'blog/getBlog',
    params: {
      blogId: id
    }
  })
}
//点赞
export function like(id: number) {
  return request({
    method: 'post',
    url: 'blog/like',
    params: {
      blogId: id
    }
  })
}
//取消点赞
export function revokeLike(id: number) {
  return request({
    method: 'delete',
    url: 'blog/revokeLike',
    params: {
      blogId: id
    }
  })
}
//查询博客
export function searchBlog(params?: BlogParams) {
  return request({
    method: 'get',
    url: 'blog/searchBlog',
    params: params
  })
}
//评论
export function makeComment(comment: string, id: number) {
  return request({
    method: 'post',
    url: 'blog/comment',
    params: {
      blogId: id,
      comment: comment
    }
  })
}
//获取评论
export function getComment(id: number) {
  return request({
    method: 'get',
    url: 'blog/getComment',
    params: {
      blogId: id
    }
  })
}

//发布博客
//上传博客内图片
export function upLoadBlogImage(img: File) {
  return request({
    method: 'post',
    url: 'blog/uploadBlogImage',
    data: {
      fileToUpload: img
    },
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
//发布博客正文
export function publishBlog(title: string, content: string, abstract?: string, img?: File) {
  return request({
    method: 'post',
    url: 'blog/publishBlog',
    data: {
      title: title,
      content: content,
      digest: abstract,
      previewImage: img
    },
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
//删除博客
export function revokeBlog(id: number) {
  return request({
    method: 'delete',
    url: 'blog/revokeBlog',
    params: {
      blogId: id
    }
  })
}
